<template>
	<view class="administrator">
		<view v-if="state">
		<view class="administrator-card" v-if="data.length != 0">
			<uni-card :is-shadow="false" :border="false" :margin="'20rpx'" :spacing="'20rpx 40rpx'" :padding="0" v-for="item in data" :key="item.id" @tap="goinfo(item)">
				<view class="u-list">
					<view class="list-view">
					   <view>
					   	<text class="text text1">{{item.real_name || item.nickname}}</text>
						<text class="text">{{item.phone || ''}}</text>
					   </view>
					   <!-- <view @click="deleClick(item.id)">
					   	<uni-icons type="clear" color="#e6e6e6" :size="'32r'"/>
					   </view> -->
					</view>
				</view>
			</uni-card>
		</view>
		</view>
		<view style="width: 100%;display: flex;flex-direction: column;justify-content: center;align-items: center;height: 100%;" v-else>
			<image :src="imgUrl" style="width: 350rpx;height:291rpx;margin-bottom: 36rpx;"></image>
			<text style="font-size: 32rpx;font-weight: 500;color: #777777;margin-bottom: 120rpx;">暂无数据!</text>
		</view>	
		<view class="administrator-but">
			<button class="but" plain @click="administrator('administrator-up')">添加管理员</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				imgUrl:`${getApp().globalData.imgScr}jd/dingdankongzhuangtai.png`,
				url:'/hotelAdmin/my/administrator',
				data:[],
				state:true, // 默认状态
			};
		},
		onShow() {
			this.getClick()
		},
		onPullDownRefresh() {
			let _this = this
			// 下拉刷新时触发
		        setTimeout(function () {
					uni.showToast({
						title:"刷新成功",
						icon:"none"
					})
					// 重置 data() 数据
					Object.assign(_this.$data, _this.$options.data())
					_this.getClick()
		            uni.stopPullDownRefresh();
		        }, 1000);
		    },
		methods:{
			/**
			 * 添加管理员
			 * @param {string} path 跳转的页面地址
			 */
			administrator(path) {
					uni.navigateTo({
						url: `${this.url}/${path}/${path}`,
					});
			},
			goinfo(item){
				uni.navigateTo({
					url: '/hotelAdmin/my/administrator/administrator-up/administrator-up?id=' + item.id + "&hotel_ids=" + item.hotel_id_arr + "&phone=" + item.phone
				})
			},
			/**
			 * 删除按钮
			 * @param {number} i 当前列表的id
			 */
			async deleClick(id) {
				console.log('删除',id)
				try {
					let res = await this.$http.post('/index/Hotelpersonal/del_admin',{id:id})
					console.log('删除成功',res)
					this.getClick()
					uni.showToast({
						title: '删除成功',
						icon:'none',
					});
				}catch (e) {
					uni.showToast({
						title: e.errMsg,
						icon:"none"
					})
				}
			},
			/**
			 * 请求数据
			 */
			async getClick() {
				let _this = this
				try{
					let res = await this.$http.post('/index/Hotelpersonal/admin_list')
					this.data = res
					this.state = this.data.length
				}catch(e){
					//TODO handle the exception
					uni.showToast({
						title: e.errMsg,
						icon:"none"
					})
				}
			},
		}
	}
</script>

<style lang="scss">
.administrator {
	display: flex;
	flex-direction: column;
	justify-content: space-between;
	height: 100vh;
	.administrator-card {
		flex: 1;
		overflow: auto;
		margin-bottom: 20rpx;
		.uni-card {
			border-radius: 20rpx;
		}
		.u-list {
			padding: 10rpx 0;
			.list-view {
				display: flex;
				justify-content: space-between;
				align-items: center;
				.text {
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #000000;
				}
				.text1 {
					display: inline-block;
					width: 150rpx;
				}
			}
		}
	}
	.administrator-but {
		width: 100%;
		height: 80rpx;
		margin-bottom: 40rpx;
		.but {
			color: #FFFFFF;
			background: linear-gradient(-90deg, #8dc9f1, #d8eefc);
			border-radius: 40rpx;
			line-height: 80rpx;
			border: 0;
			margin: 0 20rpx;
		}
	}
}
</style>
